package com.itbaizhan.listener;

import com.alibaba.fastjson.JSON;
import com.itbaizhan.domain.TxLog;
import com.itbaizhan.mapper.TxLogMapper;
import com.itbaizhan.service.StockService;
import com.itbaizhan.tx.TxMessage;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author spf
 * @date 2024/4/23
 * @time 14:35
 */
@Component
@RocketMQMessageListener(consumerGroup = "tx_stock_group", topic = "tx_msgtopic")
public class StockTxMessageConsumer implements RocketMQListener<String> {

    @Autowired
    private StockService stockService;

    @Override
    public void onMessage(String message) {
        TxMessage txMessage = JSON.parseObject(message, TxMessage.class);

        stockService.decreaseStock(txMessage);
    }
}
